//InnerAudioContext实例
//const app = getApp()
//InnerAudioContext实例
var audioCxt;
//动画
//var audioAnimation;
audioCxt = wx.createInnerAudioContext();
//audioCxt.src = 'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/audio/daziqin0.mp3';
 
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tips: {
      type: Array,
      value: [],
      observer: function (n) {
        if (n.length) {
          n.forEach(item => {
            if (item.type == 'warn') {
              item.w = item.tip_content.length * 40;
            } else {
              item.w = item.btn.length * 120;
            }

          })
          this.setData({
            tipsArr: n
          })
        }
      }
    },
    tip0: {
      type: String,
      value: '',
      observer: function (n) {
        if (n.length) {
          this.setData({
            tip0: n
          })
        }
      }
    },
    tip1: {
      type: String,
      value: '',
      observer: function (n) {
        if (n.length) {
          this.setData({
            tip1: n
          })
        }
      }
    },
    tip2: {
      type: String,
      value: '',
      observer: function (n) {
        if (n.length) {
          this.setData({
            tip2: n
          })
        }
      }
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    play0:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/0.png',
    play1:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/1.png',
    play2:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/2.png',
    play3:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/3.png',
    play4:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/4.png',
    play5:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/5.png',
    play6:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/6.png',
    play7:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/7.png',
    play8:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/8.png',
    play9:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/9.png',
    playstar:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/star.png',
    playpound:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/pound.png',
    playok:'1598',
    playdata:'',
    count:0,
  },
  /**
  * 页面加载完成执行
  */
 lifetimes:{
  ready(){
    var that =this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        // 屏幕宽度、高度
        console.log('height=' + res.windowHeight);
        console.log('width=' + res.windowWidth);
        // 高度,宽度 单位为px
        that.setData({
          windowHeight:  res.windowHeight,
          windowWidth:  res.windowWidth,
          //buttonTop1:buttonTop1,//这里定义按钮的初始位置
          //buttonLeft:res.windowWidth*0.70,//这里定义按钮的初始位置
        })
      }
    })

    //在播放状态，绑定播放进度更新事件。然后控制进度条和时间显示
    audioCxt.onPlay((res) =>{ 
      //audioCxt.onTimeUpdate(this.timeUpdate)
      console.log('播放start')
    }),
    //音乐播放结束触发
    audioCxt.onEnded((res)=>{
      audioCxt.seek(0);
      console.log('播放end')
    })
    

  },
  attached: function() {
    // 在组件实例进入页面节点树时执行
  },
  detached: function() {
    // 在组件实例被从页面节点树移除时执行
  },
},
 //组件所在页面的生命周期
 pageLifetimes: {
  show: function() {
    // 页面被展示
  },
  hide: function() {
    // 页面被隐藏
  },
  resize: function(size) {
    // 页面尺寸变化
  }
},
   /**
   * 组件的方法列表
   */
  methods: {
    //播放按钮事件
    playMusic : function(e){
      var that = this;
      let play = e.currentTarget.dataset.play;
      if(play=='*'){
        play='star';
      }
      else if(play=='#'){
        play='pound';
      }
      var mp3 = 'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/dtmf-'+play+'_1.mp3';
      var img = 'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/'+play+'.png';
      audioCxt.src = mp3;
      audioCxt.play();
      let top = 'play'+play;
      this.data.playdata = this.data.playdata+play;
      this.setData({
        [top]: img,
        playdata:this.data.playdata,
      })
      if(this.data.playdata==this.data.playok){
        wx.showToast({
          title: '门开了！',  // 标题
          icon: 'success',   // 图标类型，默认success
          duration: 1500   // 提示窗停留时间，默认1500ms
        })
      }
      console.log(play+' '+top+' '+img +' '+this.data.playdata)
      //console.log(this.data.play1)
    },
    playReset:function(){
      
      this.setData({
        play0:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/0.png',
    play1:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/1.png',
    play2:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/2.png',
    play3:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/3.png',
    play4:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/4.png',
    play5:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/5.png',
    play6:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/6.png',
    play7:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/7.png',
    play8:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/8.png',
    play9:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/9.png',
    playstar:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/star.png',
    playpound:'https://game-lake.oss-cn-beijing.aliyuncs.com/linglong/tingmima/no/pound.png',
        playdata:'',
      })
      this.onLoad();//重新加载
    },
    /*
     * 内部私有方法建议以下划线开头
     * triggerEvent 用于触发事件
     */
    _okEvent(){
      //触发取消回调
      var that = this;
      console.log('触发取消回调')
      var isOk = 0;
      if(that.data.count>=2){
        isOk = 1;
      }
      return isOk;
      //this.triggerEvent("cancelEvent")
    },
        //暂停按钮事件
        pauseMusic : function(){
          audioCxt.pause();
        },
  

  uniqueStr (array){
    return array.filter(function(el, index, arr) {
    return index == arr.indexOf(el);
    });
  },
  }
})